package com.riant.mybatis.service.impl;

import com.github.pagehelper.PageHelper;
import com.riant.mybatis.bean.WebSite;
import com.riant.mybatis.dao.WebSiteMapper;
import com.riant.mybatis.service.WebSiteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname WebSiteServiceImpl
 * @Description TODO
 * @Date 2021/6/3 22:31
 * @Created by 张斌
 */
@Service("webSiteService")
public class WebSiteServiceImpl implements WebSiteService {

    @Autowired
    private WebSiteMapper webSiteMapper;

    @Override
    public WebSite getWebSite(int id) {
        return webSiteMapper.selectWebSiteById(id);
    }

    @Override
    public List<WebSite> getAllWebSite() {
        return webSiteMapper.selectAllWebSite();
    }

    /*
     * 这个方法中springboot分页插件pagehelper
     * 很简单，只需要在service层传入参数，然后将参数传递给一个插件的一个静态方法即可；
     * pageNum 开始页数
     * pageSize 每页显示的数据条数
     * */
    @Override
    public List<WebSite> getAllWebSite(int pageNum, int pageSize) {
        //将参数传给这个方法就可以实现物理分页了，非常简单。
        PageHelper.startPage(pageNum, pageSize);
        return webSiteMapper.selectAllWebSite();
    }

    @Override
    public Integer updateWebSite(WebSite webSite) {
        return webSiteMapper.updateWebSiteById(webSite);
    }

    @Override
    public Integer insertWebSite(WebSite webSite) {
        return webSiteMapper.insertWebSite(webSite);
    }

    @Override
    public Integer deleteWebSite(int id) {
        return webSiteMapper.deleteById(id);
    }
}
